package exer;

/**给定一个链表，删除链表的倒数第 n 个结点，并且返回链表的头结点
 * @author shkstart
 * @create 2022-08-14-17:13
 */
public class jian2_21 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode low = head;
        ListNode fast = head;
        for (int i = 0; i < n; i++) {
            low=low.next;
        }
        while (low != null) {
            low=low.next;
            fast = fast.next;
        }
        fast.next = fast.next.next;
        return head;
    }
}
